package com.caseprocessing.api;

import java.util.List;
import java.util.Map;

/**
 * AI文档分析结果模型
 * 封装AI对文档的分析结果
 */
public class DocumentAnalysisResult {
    
    private String analysisType;
    private String documentType;
    private Double confidence;
    private String rawContent;
    private Map<String, Object> structuredData;
    private List<String> issues;
    private List<String> suggestions;
    private AnalysisMetadata metadata;
    
    public DocumentAnalysisResult() {}
    
    public String getAnalysisType() {
        return analysisType;
    }
    
    public void setAnalysisType(String analysisType) {
        this.analysisType = analysisType;
    }
    
    public String getDocumentType() {
        return documentType;
    }
    
    public void setDocumentType(String documentType) {
        this.documentType = documentType;
    }
    
    public Double getConfidence() {
        return confidence;
    }
    
    public void setConfidence(Double confidence) {
        this.confidence = confidence;
    }
    
    public String getRawContent() {
        return rawContent;
    }
    
    public void setRawContent(String rawContent) {
        this.rawContent = rawContent;
    }
    
    public Map<String, Object> getStructuredData() {
        return structuredData;
    }
    
    public void setStructuredData(Map<String, Object> structuredData) {
        this.structuredData = structuredData;
    }
    
    public List<String> getIssues() {
        return issues;
    }
    
    public void setIssues(List<String> issues) {
        this.issues = issues;
    }
    
    public List<String> getSuggestions() {
        return suggestions;
    }
    
    public void setSuggestions(List<String> suggestions) {
        this.suggestions = suggestions;
    }
    
    public AnalysisMetadata getMetadata() {
        return metadata;
    }
    
    public void setMetadata(AnalysisMetadata metadata) {
        this.metadata = metadata;
    }
    
    /**
     * 检查分析是否成功
     */
    public boolean isSuccessful() {
        return confidence != null && confidence > 0.0;
    }
    
    /**
     * 检查置信度是否足够高
     */
    public boolean hasHighConfidence() {
        return confidence != null && confidence >= 0.8;
    }
    
    /**
     * 获取特定字段的结构化数据
     */
    public Object getStructuredField(String fieldName) {
        if (structuredData != null) {
            return structuredData.get(fieldName);
        }
        return null;
    }
    
    /**
     * 分析元数据
     */
    public static class AnalysisMetadata {
        private String modelUsed;
        private Long processingTimeMs;
        private Integer tokensUsed;
        private String analysisDateTime;
        private String version;
        
        public AnalysisMetadata() {}
        
        public String getModelUsed() {
            return modelUsed;
        }
        
        public void setModelUsed(String modelUsed) {
            this.modelUsed = modelUsed;
        }
        
        public Long getProcessingTimeMs() {
            return processingTimeMs;
        }
        
        public void setProcessingTimeMs(Long processingTimeMs) {
            this.processingTimeMs = processingTimeMs;
        }
        
        public Integer getTokensUsed() {
            return tokensUsed;
        }
        
        public void setTokensUsed(Integer tokensUsed) {
            this.tokensUsed = tokensUsed;
        }
        
        public String getAnalysisDateTime() {
            return analysisDateTime;
        }
        
        public void setAnalysisDateTime(String analysisDateTime) {
            this.analysisDateTime = analysisDateTime;
        }
        
        public String getVersion() {
            return version;
        }
        
        public void setVersion(String version) {
            this.version = version;
        }
        
        @Override
        public String toString() {
            return "AnalysisMetadata{" +
                    "modelUsed='" + modelUsed + '\'' +
                    ", processingTimeMs=" + processingTimeMs +
                    ", tokensUsed=" + tokensUsed +
                    ", analysisDateTime='" + analysisDateTime + '\'' +
                    ", version='" + version + '\'' +
                    '}';
        }
    }
    
    /**
     * 结果构建器
     */
    public static ResultBuilder builder() {
        return new ResultBuilder();
    }
    
    public static class ResultBuilder {
        private String analysisType;
        private String documentType;
        private Double confidence;
        private String rawContent;
        private Map<String, Object> structuredData;
        private List<String> issues;
        private List<String> suggestions;
        private AnalysisMetadata metadata;
        
        public ResultBuilder analysisType(String analysisType) {
            this.analysisType = analysisType;
            return this;
        }
        
        public ResultBuilder documentType(String documentType) {
            this.documentType = documentType;
            return this;
        }
        
        public ResultBuilder confidence(Double confidence) {
            this.confidence = confidence;
            return this;
        }
        
        public ResultBuilder rawContent(String rawContent) {
            this.rawContent = rawContent;
            return this;
        }
        
        public ResultBuilder structuredData(Map<String, Object> structuredData) {
            this.structuredData = structuredData;
            return this;
        }
        
        public ResultBuilder issues(List<String> issues) {
            this.issues = issues;
            return this;
        }
        
        public ResultBuilder suggestions(List<String> suggestions) {
            this.suggestions = suggestions;
            return this;
        }
        
        public ResultBuilder metadata(AnalysisMetadata metadata) {
            this.metadata = metadata;
            return this;
        }
        
        public DocumentAnalysisResult build() {
            DocumentAnalysisResult result = new DocumentAnalysisResult();
            result.setAnalysisType(analysisType);
            result.setDocumentType(documentType);
            result.setConfidence(confidence);
            result.setRawContent(rawContent);
            result.setStructuredData(structuredData);
            result.setIssues(issues);
            result.setSuggestions(suggestions);
            result.setMetadata(metadata);
            return result;
        }
    }
    
    @Override
    public String toString() {
        return "DocumentAnalysisResult{" +
                "analysisType='" + analysisType + '\'' +
                ", documentType='" + documentType + '\'' +
                ", confidence=" + confidence +
                ", rawContent='" + (rawContent != null ? rawContent.substring(0, Math.min(100, rawContent.length())) + "..." : null) + '\'' +
                ", structuredData=" + structuredData +
                ", issues=" + issues +
                ", suggestions=" + suggestions +
                ", metadata=" + metadata +
                '}';
    }
}